<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="成分类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zttype">
              <a-input v-model="model.zttype" placeholder="请输入成分类别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中文名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztcnname">
              <a-input v-model="model.ztcnname" placeholder="请输入中文名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="INCI名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztenname">
              <a-input v-model="model.ztenname" placeholder="请输入INCI名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztremark">
              <a-input v-model="model.ztremark" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用目的" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zttarget">
              <a-input v-model="model.zttarget" placeholder="请输入使用目的"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="外观性状" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztappearance">
              <a-input v-model="model.ztappearance" placeholder="请输入外观性状"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="CI号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztci">
              <a-input v-model="model.ztci" placeholder="请输入CI号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztsequence">
              <a-input v-model="model.ztsequence" placeholder="请输入序号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="材料来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztmatsource">
              <a-input v-model="model.ztmatsource" placeholder="请输入材料来源"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注（材料来源）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztmatremark">
              <a-input v-model="model.ztmatremark" placeholder="请输入备注（材料来源）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="CAS号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztcas">
              <a-input v-model="model.ztcas" placeholder="请输入CAS号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="稳定性等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztstability">
              <a-input v-model="model.ztstability" placeholder="请输入稳定性等级"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="微生物敏感等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztsensible">
              <a-input v-model="model.ztsensible" placeholder="请输入微生物敏感等级"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="保质期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztquqntity">
              <a-input v-model="model.ztquqntity" placeholder="请输入保质期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="储存条件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztstore">
              <a-input v-model="model.ztstore" placeholder="请输入储存条件"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开封后储存条件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztopenstore">
              <a-input v-model="model.ztopenstore" placeholder="请输入开封后储存条件"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="注意事项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztcaution">
              <a-input v-model="model.ztcaution" placeholder="请输入注意事项"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用要求" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztuserequire">
              <a-input v-model="model.ztuserequire" placeholder="请输入使用要求"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="急性毒性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztviru">
              <a-input v-model="model.ztviru" placeholder="请输入急性毒性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="刺激性/腐蚀性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztcj">
              <a-input v-model="model.ztcj" placeholder="请输入刺激性/腐蚀性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="致敏性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztzm">
              <a-input v-model="model.ztzm" placeholder="请输入致敏性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="光毒性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgt">
              <a-input v-model="model.ztgt" placeholder="请输入光毒性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="光变态反应" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztgbt">
              <a-input v-model="model.ztgbt" placeholder="请输入光变态反应"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="致突变性/遗传毒性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztycdx">
              <a-input v-model="model.ztycdx" placeholder="请输入致突变性/遗传毒性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="重复剂量毒性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztcfjldx">
              <a-input v-model="model.ztcfjldx" placeholder="请输入重复剂量毒性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生殖发育毒性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztszfytx">
              <a-input v-model="model.ztszfytx" placeholder="请输入生殖发育毒性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="慢性毒性/致癌性" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztmxdx">
              <a-input v-model="model.ztmxdx" placeholder="请输入慢性毒性/致癌性"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="毒代动力学" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztdddlx">
              <a-input v-model="model.ztdddlx" placeholder="请输入毒代动力学"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="人体试验" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztrtsy">
              <a-input v-model="model.ztrtsy" placeholder="请输入人体试验"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ztother">
              <a-input v-model="model.ztother" placeholder="请输入其他"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ZtMatcomponentForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           zttype: [
              { required: true, message: '请输入成分类别!'},
           ],
           ztcnname: [
              { required: true, message: '请输入中文名称!'},
           ],
           ztenname: [
              { required: true, message: '请输入INCI名称!'},
           ],
           ztci: [
              { required: true, message: '请输入CI号!'},
           ],
           ztsequence: [
              { required: true, message: '请输入序号!'},
           ],
           ztmatsource: [
              { required: true, message: '请输入材料来源!'},
           ],
           ztmatremark: [
              { required: true, message: '请输入备注（材料来源）!'},
           ],
           ztcas: [
              { required: true, message: '请输入CAS号!'},
           ],
        },
        url: {
          add: "/roles/ztMatcomponent/add",
          edit: "/roles/ztMatcomponent/edit",
          queryById: "/roles/ztMatcomponent/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>